'use strict'

class login{

  constructor (mdb) {
    this.mdb = mdb || null
  }

  async insert(d) {
    //创建树洞需要插入的数据 uimg 
    
    let data=JSON.parse(d)
    console.log('----------------------------------------------------------');
    console.log("这是data数据：",data)
    //console.log("data.uid:",data.uid)
    //console.log(typeof(data.uimg));
    //console.log(data.uimg)

    //let sql2=`select * from users where uimg=${data.uimg}` 
    //let r2=await config.query(sql2)
    //let result=r2['rows']
    //console.log(result)
     
    //if(data.uid==''){
      let sql='select * from users';
      let r=await this.mdb.query(sql);
      
      let uid=r['rows'].length+1; 
      
      this.mdb.connect().then(client=>{
        client.query('insert into users values($1::int,$2::varchar(20),$3::int,$4::int,$5::text,$6::text,$7::text,$8::text)',[uid,data.uname,uid,0,'','','',data.uimg]).then(res=>{
          
        })
      })
      
      return {'uid':uid}
      
    //}else{
      //return '你已登录'
    //}
    
  }

    


    
 
}

module.exports = login
